package co.yixiang.modules.shop.rest;

import co.yixiang.aop.log.Log;
import co.yixiang.modules.shop.domain.YxStoreQuestionnaire;
import co.yixiang.modules.shop.service.YxStoreQuestionnaireService;
import co.yixiang.modules.shop.service.dto.YxStoreQuestionnaireQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
* @author frq
* @date 2020-05-29
*/
@Api(tags = "投资管理管理")
@RestController
@RequestMapping("/api/yxStoreQuestionnaire")
public class YxStoreQuestionnaireController {
    @Autowired
    private  YxStoreQuestionnaireService yxStoreQuestionnaireService;
    @GetMapping
    @Log("查询投资管理")
    @ApiOperation("查询投资管理")
//    @PreAuthorize("@el.check('yxStoreQuestionnaire:list')")
    public ResponseEntity<Object> getYxStoreQuestionnaires(YxStoreQuestionnaireQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxStoreQuestionnaireService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增投资管理")
    @ApiOperation("新增投资管理")
//    @PreAuthorize("@el.check('yxStoreQuestionnaire:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody YxStoreQuestionnaire resources){
        resources.setAddTime(new Date());
        return new ResponseEntity<>(yxStoreQuestionnaireService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改投资管理")
    @ApiOperation("修改投资管理")
//    @PreAuthorize("@el.check('yxStoreQuestionnaire:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody YxStoreQuestionnaire resources){
        yxStoreQuestionnaireService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除投资管理")
    @ApiOperation("删除投资管理")
//    @PreAuthorize("@el.check('yxStoreQuestionnaire:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
        yxStoreQuestionnaireService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}